<?php
    echo '<h4 id="repost" style="color: red; font-weight: normal; margin: 10px 0;"></h4>';
    echo $this->Form->create('Cateroom', array('action'=>'access_price'));
    echo $this->Form->input('id', array('type' => 'hidden', 'value' => $id));
?>
    <table cellspacing="0" cellpadding="0" width="100%" id="adg" style="margin-bottom: 0;">
        <tr style="background: none;">
            <th style="text-align: left; width: 36%; border: none;" valign="top">
                <ul class="pri-day">
                    <li style="display: none">
                        <?php echo $this->Form->input('tim', array('style' => 'width: 30px', 'label' => false, 'div' => false)); ?>&nbsp; &nbsp;
                        <label>Giờ</label>&nbsp; &nbsp;
                        <?php echo $this->Form->input('pri', array('style' => 'width: 70px', 'label' => false, 'div' => false)); ?>&nbsp;&nbsp;<label>VNĐ</label><a href="javascript:void(0)" class="remove">Xóa</a>
                    </li>
                    <li style="margin-bottom: 16px;"><span style="width: 190px; display: block; float: left;">Theo giờ </span><span class="extend" style="font-size: 12px; color: #006699; font-weight: normal; cursor:pointer;">Thêm mới &darr;</span></li>
                    <?php
                        foreach ($prt as $key => $value) {
                            if($value['PriceTime']['type'] == 1){
                    ?>
                            <li>
                                <?php echo $this->Form->input('idpth.', array('type' => 'hidden', 'value' => $value['PriceTime']['id'])) ?>
                                <?php echo $this->Form->input('timeh.', array('style' => 'width: 30px', 'label' => false, 'div' => false, 'value' => $value['PriceTime']['time'])); ?>&nbsp; &nbsp;
                                <label>Giờ</label>&nbsp; &nbsp;
                                <?php echo $this->Form->input('priceh.', array('style' => 'width: 70px', 'label' => false, 'div' => false, 'value' => $value['PriceTime']['price'])); ?>&nbsp;&nbsp;<label>VNĐ</label><a href="<?php echo $this->webroot.'PriceTimes/delete/'.$value['PriceTime']['id'] ?>" 
                                id="<?php echo $value['PriceTime']['id']; ?>" class="remove">Xóa</a>
                            </li>
                    <?php
                                unset($prt[$key]);
                            }
                        }
                    ?>
                </ul>
                <ul style="margin-top: 30px;" class="pri-night">
                    <li style="margin-bottom: 8px;"><span style="width: 190px; display: block; float: left;">Giá qua đêm nhận phòng sau </span><span class="extend1" style="font-size: 12px; color: #006699; font-weight: normal; cursor:pointer;">Thêm mới &darr;</span></li>
                    <?php
                        foreach ($prt as $k => $v) {
                    ?>
                            <li>
                                <?php echo $this->Form->input('idptn.', array('type' => 'hidden', 'value' => $v['PriceTime']['id'])) ?>
                                <?php echo $this->Form->input('timeon.', array('style' => 'width: 30px', 'label' => false, 'div' => false, 'value'=> $v['PriceTime']['time'])); ?>&nbsp; &nbsp;
                                <label>Giờ</label>&nbsp; &nbsp;
                                <?php echo $this->Form->input('priceon.', array('style' => 'width: 70px', 'label' => false, 'div' => false, 'value' => $v['PriceTime']['price'])); ?>&nbsp;&nbsp;<label>VNĐ</label><a href="<?php echo $this->webroot.'PriceTimes/delete/'.$v['PriceTime']['id'] ?>" id="<?php echo $v['PriceTime']['id'] ?>" class="remove">Xóa</a>
                            </li>
                    <?php } ?>
                </ul>
            </th>
            <th style="text-align: left; width: 22%; border: none;" valign="top">
                <ul>
                    <li style="margin-bottom: 16px;">Theo ngày</li>
                    <li><?php echo $this->Form->input('price_date', array('div' => false, 'type' => 'text', 'label' => false, 'value' => $pr['Cateroom']['price_date'], 'style' => 'width: 90px;')); ?>&nbsp;&nbsp;<label>VNĐ</label></li>
                    <li style="margin: 8px 0;">Theo tuần</li>
                    <li><?php echo $this->Form->input('price_week', array('div' => false, 'type' => 'text', 'label' => false, 'value' => $pr['Cateroom']['price_week'], 'style' => 'width: 90px;')); ?>&nbsp;&nbsp;<label>VNĐ</label></li>
                    <li style="margin: 8px 0;">Theo tháng</li>
                    <li><?php echo $this->Form->input('price_month', array('div' => false, 'type' => 'text', 'label' => false, 'value' => $pr['Cateroom']['price_month'], 'style' => 'width: 90px;')); ?>&nbsp;&nbsp;<label>VNĐ</label></li>
                </ul>
            </th>
            <th style="width: 42%; text-align: left; border: none;" valign="top">
                <ul id="over-peo">
                    <li style="display: none;"><span style="margin-right: 10px">Nếu quá</span><?php echo $this->Form->input('people', array('div' => false, 'label' => false, 'style' => 'width: 30px; margin-right: 10px;')) ?><span style="margin-right: 10px;">người cộng thêm</span><?php echo $this->Form->input('pricep', array('div' => false, 'label' => false, 'style' => 'width: 90px')); ?><a href="javascript:void(0)" class="remove">Xóa</a></li>
                    <li style="margin-bottom: 16px"><span style="width: 303px; display: block; float: left;">Theo số người vượt quá</span><span class="extend2" style="font-size: 12px; color: #006699; font-weight: normal; cursor:pointer;">Thêm mới &darr;</span></li>
                    <?php
                        foreach ($over_people as $op) {
                            echo $this->Form->input('idop.', array('type' => 'hidden', 'value' => $op['OverPeople']['id']));
                    ?>
                        <li><span style="margin-right: 10px">Nếu quá</span><?php echo $this->Form->input('people.', array('div' => false, 'label' => false, 'style' => 'width: 30px; margin-right: 10px;', 'value' => $op['OverPeople']['people'])) ?><span style="margin-right: 10px">người cộng thêm</span><?php echo $this->Form->input('priceop.', array('div' => false, 'label' => false, 'style' => 'width: 90px;', 'value' => $op['OverPeople']['price'])); ?><a href="<?php echo $this->webroot.'OverPeoples/delete/'.$op['OverPeople']['id'] ?>" id="<?php echo $op['OverPeople']['id'] ?>" class="remove">Xóa</a></li>
                    <?php } ?>
                </ul>
            </th>
        </tr>
    </table>
<?php echo $this->Form->end('Cập nhật'); ?>
<style>
    .submit{
        margin-bottom: 10px;
    }
    input[type='submit']{
        padding: 4px 14px;
        border: 1px solid #C0C0C0;
        cursor: pointer;
    }
</style>
<script type="text/javascript">
    jQuery(document).ready(function($) {

        $("input[type='text']").keypress(function (e) {
            if(e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                return false;
            }
        });
        $(document).on('submit', 'form', function(event) {
            var arr_peo = [];
            var f = true;
            $("input[name='data[Cateroom][people][]']").each(function(index, el) {
                var peo = parseInt($(this).val());
                if($.inArray(peo,arr_peo) != -1 || peo == 0){
                    f = false;
                    return false;
                }
                arr_peo.push(peo);
            });

            if(f == false){
                event.preventDefault();
                $('#repost').html('Số người vượt quá không được trùng nhau và phải khác 0');
            }

            var pri_date = parseInt($('#CateroomPriceDate').val());
            var pri_week = parseInt($('#CateroomPriceWeek').val());
            var pri_month = parseInt($('#CateroomPriceMonth').val());
            if(pri_date >= pri_week || pri_date >= pri_month || pri_week >= pri_month){
                event.preventDefault();
                $('#repost').html('Giá theo tháng > Giá theo tuần > Giá theo ngày');
            }
            // check empty
            var f_empty = true;
            $("li:not(:hidden) input[type='text']").each(function(index, el) {
                var cur_val = $(this).val();
                if(parseInt(cur_val) == 0 || cur_val == ''){
                    f_empty = false;
                    return false;
                }
            });
            if(f_empty == false){
                event.preventDefault();
                $('#repost').html('Các trường dữ liệu không được trống và phải khác 0');
            }
            
           
        });
    })
</script>
